<?php

namespace app\admin\model;

use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Db;
use think\Model;

class OrderServiceSales extends Model
{

    // 表名
    protected $name = 'order_service_sales';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [

    ];

    public function getOriginData()
    {
        return $this->origin;
    }


    public function getGenderList()
    {
        return ['1' => __('Male'), '0' => __('Female')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }


    public function getPrevtimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['prevtime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getLogintimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['logintime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getJointimeTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['jointime'] ?? "");
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPrevtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setLogintimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setJointimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setBirthdayAttr($value)
    {
        return $value ? $value : null;
    }

    public function school()
    {
        return $this->belongsTo('SchoolClass', 'school_class_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function trusteeshipType()
    {
        return $this->belongsTo('TrusteeshipType', 'tg_type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function order1()
    {
        return $this->belongsTo('StoreOrder', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * 关联售后
     */
    public function service()
    {
        return $this->belongsTo(Service::class, 'service_id', 'service_id');
    }
    /**
     * 关联售后
     */
    public function lift()
    {
        return $this->belongsTo(Lift::class, 'lift_id', 'id');
    }


    public function  getDetailArr($row){
//        if($row['check_time'] >0){
//            $row['check_time'] = date('Y-m-d H:i:s',$row['check_time']);
//        }
//        if($row['submit_check_time'] >0){
//            $row['submit_check_time'] = date('Y-m-d H:i:s',$row['submit_check_time']);
//        }else{
//            $row['submit_check_time'] = '-';
//        }
        if($row['add_time'] >0){
            $row['add_time'] = date('Y-m-d H:i:s',$row['add_time']);
        }
        $row['service'] = Db::name('store_order_service')->where(['service_id'=>$row['service_id']])->find();
        $row['lift'] = Db::name('lift')->where(['id'=>$row['service']['lift_id']])->find();
        $row['order'] = Db::name('store_order')->where(['order_id'=>$row['service']['order_id']])->find();
        if($row['remark'] ==1){
            $row['remark_text'] = '电梯损坏';
        }else if($row['remark'] ==2){
            $row['remark_text'] = '保洁员态度恶劣';
        }else{
            $row['remark_text'] = '其他';
        }
        if($row['order']['pay_time'] >0){
            $row['order']['pay_time'] = date('Y-m-d H:i:s',$row['order']['pay_time']);
        }
       // $row['user'] = Db::name('user')->where(['uid'=>$row['personnel_id']])->find();
        $row['user'] = Db::name('user')->where(['uid'=>$row['order']['personnel_id']])->find();
        return $row;
    }

}
